<?php /* УТФ-8:fix */

class SPIview__enotifier extends SPIview__dummy
{
    public function render( $content, $template_name )
    {
        $tpl = SPItpl::I('enotifier');

        $tpl->assign_by_ref('SPIcfg', SPIcfg::as_array() );
        $tpl->assign_by_ref('content', $content);

        $tpl_message = $tpl->compile($template_name);
        $tpl_message = explode( "\n", trim( $tpl_message ) );

        //-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

        $message = array();

        foreach( $tpl_message as $line )
        {
            $line = trim( $line );

            if( strpos( $line, '#subject#' ) === 0 )
            {
                $subject = trim( str_replace( '#subject#', '', $line ) );
            }
            else
            {
                $message[] = $line;
            }
        }

        $message = trim( join( "\n", $message ) );

        //-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

        return array( $subject, $message );
    }
}
